<template>
  <div class="find">
    <!-- 顶部栏 -->
    <van-pull-refresh v-model="isLoading" @refresh="onRefresh">
      <van-list
        v-model="loading"
        :finished="finished"
        finished-text="到底了"
        @load="onLoad"
      >
        <van-nav-bar title="发现" />
        <van-cell value="发现更多" is-link title="面试技巧" />
        <!-- 文章列表 -->
        <div class="wz" v-for="item in list" :key="item.id">
          <div class="left">
            <h3>{{ item.title }}</h3>
            <span>1年前</span>
            <van-icon name="eye-o">1</van-icon>
            <van-icon name="good-job-o">46</van-icon>
          </div>
          <div class="right">
            <img :src="`http://localhost:1337${item.cover}`" alt="" />
          </div>
        </div>

        <!-- 市场数据 -->
        <van-cell value="查看更多" is-link title="市场数据" @click="scback" />
        <div class="sc" v-if="show">
          <span class="shic">{{ htlist.city }}</span
          ><span class="yj">{{ htlist.position }}</span>
          <div
            class="jdt"
            v-for="(item, index) in htlist.yearSalary"
            :key="index"
          >
            <span>{{ item.year | newyear }}</span>
            <div class="center">
              <div class="one" :style="{ width: percents(item.salary) }">
                {{ `${item.salary}$ ` }}
              </div>
              <span class="two"> <van-icon name="down" class="icon" /></span
              ><span> {{ `${item.percent}%` }}</span>
            </div>
          </div>
        </div>
        <!-- 显示展开 -->
        <div class="zk">
          <span
            >{{ tname
            }}<van-icon
              :name="show ? 'arrow-up' : 'arrow-down'"
              style="text-align=center"
              @click="showback"
            ></van-icon
          ></span>
        </div>
        <!-- 面经分享 -->
        <van-cell value="查看更多" is-link title="面经分享" @click="bcgd" />
        <div
          class="mj"
          v-for="(item, index) in articleslist"
          :key="index"
          @click="$router.push({ path: '/labour', query: { id: item.id } })"
        >
          <h3>{{ item.title }}</h3>
          <p>
            {{ item.content }}
          </p>
          <div class="fl">
            <div class="left">
              <span
                ><img
                  :src="`http://localhost:1337${item.author.avatar}`"
                  alt=""
                  class="login"
                />{{ item.author.nickname }}</span
              >
            </div>
            <div class="right">
              <span>1小时前</span>
              <van-icon name="more-o">1</van-icon>
              <van-icon name="good-job-o">46</van-icon>
            </div>
          </div>
        </div>
      </van-list>
    </van-pull-refresh>
  </div>
</template>

<script>
import { gettechnic, getshare, gethot } from "../../api/find";
export default {
  name: "find",
  data() {
    return {
      loading: false,
      tname: "展开更多",
      show: false,
      activeNames: ["1"],
      list: [],
      articleslist: [], //面经列表
      finished: true,
      isLoading: false,
      //城市数据
      htlist: [],
      newlist: [],
    };
  },
  methods: {
    //面试列表
    async onRefresh() {
      const res = await gettechnic({
        limit: 3,
      });
      console.log(res);
      //绑定数据
      this.list = res.data.data.list;
      //市场数据
      const rs = await gethot();
      console.log(rs);
      //绑定数据
      this.htlist = rs.data.data;
    },
    //市场数据跳转
    scback() {
      this.$router.push("/findsonn");
    },
    async onLoad() {
      //面经技巧
      const res = await getshare({
        limit: 3,
      });
      console.log(res);
      //绑定数据
      this.articleslist = res.data.data.list;
      this.loading = false;
      //保存文章id
    },
    showback() {
      this.show = !this.show;
      if (this.show) {
        this.tname = "收起列表";
      } else {
        this.tname = "展开更多";
        this.show = !true;
      }
    },
    //百分比宽度
    percents(percent) {
      return (percent / this.htlist.topSalary) * 100 + "%";
    },
    //点击查看更多跳转页面
    bcgd() {
      this.$router.push("/haves");
    },
    //根据id获取指定的数据
  },

  created() {
    this.onLoad();
    this.onRefresh();
  },

  filters: {
    newyear(value) {
      if (value.indexOf("工资") != -1) {
        return value.replace("工资", "");
      }
    },
  },
};
</script>

<style lang='less'>
* {
  padding: 0;
  margin: 0;
}
.find {
  .wz {
    display: flex;
  }
  .left {
    padding: 0 10px;
    flex: 9;
    h3 {
      font-size: 0.42667rem;
      padding: 16px 0;
    }
    span {
      padding-right: 30px;
      font-size: 0.32rem;
      color: #ccc;
    }
    .van-icon {
      margin-left: 20px;
      font-size: 0.32rem;
      color: #ccc;
    }
  }
  .right {
    padding-top: 10px;
    padding-right: 10px;
    flex: 2;
  }
  .sc {
    padding-left: 10px;
    .shic {
      padding-right: 5px;
      width: 41px;
      height: 24px;
      background: #eceaea;
      border-radius: 8px;
      font-size: 12px;
      color: #545671;
    }
    .yj {
      width: 70px;
      height: 24px;
      background: #eceaea;
      border-radius: 8px;
      font-size: 12px;
      color: #545671;
    }
  }
  .mj {
    h3 {
      padding-left: 10px;
      padding-bottom: 10px;
      font-size: 14px;
    }
    p {
      padding-left: 10px;
      font-size: 16px;
      overflow: hidden;
      font-weight: 400;
      color: #545671;
      text-overflow: ellipsis;
      white-space: nowrap;
    }
    .fl {
      display: flex;
      .left {
        padding-top: 20px;
        flex: 1;
        img {
          padding-right: 5px;
          vertical-align: top;
          width: 20px;
          height: 20px;
          border-radius: 10px;
        }
      }

      .right {
        flex: 1;
        padding-right: 20px;
        margin-top: 10px;
        span {
          font-size: 12px;
          color: #ccc;
        }
        .van-icon {
          margin-left: 20px;
          font-size: 0.32rem;
          color: #ccc;
        }
      }
    }
  }
  .jdt {
    margin-top: 10px;
    display: inline-block;
    span {
      padding-left: -40px;
      padding-right: 10px;
      font-size: 16px;
      text-align: center;
    }
    .center {
      position: relative;
      display: inline-block;
      width: 240px;
      height: 24px;
      background: #ebdfdf;
      border-radius: 8px;
      .one {
        text-align: right;
        color: #fff;
        font-weight: 400;
        width: 212px;
        height: 24px;
        background: #fe6d67;
        border-radius: 8px;
        display: inline-block;
      }
      span {
        margin-right: -55px;
        float: right;
      }
      .two {
        position: absolute;
        right: 28px;
      }
    }
  }
  .zk {
    padding-top: 10px;
    text-align: center;
    span {
      font-size: 16px;
    }
  }
}
</style>